<template>
  <common-list>
    <common-search slot="search" @search="handleQuery" @reset="resetQuery">
      <el-form
        ref="queryForm"
        :inline="true"
        :model="queryParams"
        v-show="showSearch"
        @submit.native.prevent
        label-width="65px"
      >
        <el-form-item label="应用名称" prop="applicationNameEnCode">
          <common-input
            :verify="false"
            v-model="queryParams.applicationNameEnCode"
            @enter="handleQuery"
            clearable
          />
        </el-form-item>
        <el-form-item label="所属分类" prop="parentId">
          <el-cascader
            v-model="queryParams.parentId"
            :options="applicationType"
            :props="cascaderProps"
            :show-all-levels="false"
            clearable
          >
          </el-cascader>
        </el-form-item>
        <el-form-item label="域名" prop="domain">
          <common-input
            :verify="false"
            @enter="handleQuery"
            v-model="queryParams.domain"
            clearable
          />
        </el-form-item>
        <el-form-item label="IP" prop="ip">
          <common-input
            :verify="false"
            v-model="queryParams.ip"
            clearable
            @enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="端口" prop="port">
          <common-input
            :verify="false"
            v-model="queryParams.port"
            clearable
            @enter="handleQuery"
          />
        </el-form-item>
        <common-dept
          ref="commonDept"
          :currentParent="currentParent"
          @getDeptId="getDeptId"
          @getDeptList="getDeptList"
          @getLoading="getLoading"
        ></common-dept>
        <el-form-item label="负责人" prop="principal">
          <common-input
            :verify="false"
            v-model="queryParams.principal"
            clearable
            @enter="handleQuery"
          />
        </el-form-item>
      </el-form>
    </common-search>
    <el-row :gutter="10" slot="tools">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          @click="handleAdd"
          v-hasPermi="['apisecurity:applicationManage:add']"
          >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          type="danger"
          icon="el-icon-delete"
          :disabled="!showBatch"
          @click="handleDelete"
          v-hasPermi="['apisecurity:applicationManage:remove']"
          >批量删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          type="primary"
          icon="el-icon-s-check"
          :disabled="!showBatch"
          @click="HandleDistributeOrg"
          v-hasPermi="['apisecurity:applicationManage:distribution']"
          >分配组织
        </el-button>
      </el-col>
    </el-row>

    <common-table
      slot="content"
      v-loading="loading"
      :data="licationList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="应用名称"
        align="left"
        prop="applicationName"
        show-overflow-tooltip
        fixed="left"
      />

      <!-- <el-table-column label="服务名称" align="left" prop="serverName"/> -->
      <!--      <el-table-column label="服务地址" align="left" show-overflow-tooltip>-->
      <!--        <template slot-scope="scope">-->
      <!--          <div v-for="item in scope.row.serverList">-->
      <!--            <span>{{ item.serverName }}</span>-->
      <!--            <span style="margin-left: 12px">{{-->
      <!--              item.ip + ":" + item.port-->
      <!--            }}</span>-->
      <!--          </div>-->
      <!--        </template>-->
      <!--      </el-table-column>-->

      <!--      <el-table-column label="域名" align="left" prop="domain" sortable>-->
      <!--        <template slot-scope="scope">-->
      <!--          <div>-->
      <!--            {{ scope.row.serverList[0].domain }}-->
      <!--          </div>-->
      <!--        </template>-->
      <!--      </el-table-column>-->

      <el-table-column
        label="域名"
        align="left"
        prop="serverDomain"
        width="150"
        show-overflow-tooltip
      />

      <el-table-column label="IP" prop="ip" width="160" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.serverList[0].ip }}
        </template>
      </el-table-column>
      <el-table-column
        label="应用端口"
        prop="port"
        width="100"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{ scope.row.serverList[0].port }}
        </template>
      </el-table-column>
      <el-table-column
        label="所属分类"
        prop="ancestors"
        width="200"
        show-overflow-tooltip
      />
      <el-table-column
        label="发现时间"
        prop="createTime"
        width="170"
        show-overflow-tooltip
      />
      <el-table-column
        label="接口数量"
        align="left"
        prop="interfaceCount"
        show-overflow-tooltip
        width="80"
      />
      <el-table-column
        label="组织"
        align="left"
        prop="deptName"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        label="负责人"
        align="left"
        prop="principal"
        show-overflow-tooltip
        width="100"
      />
      <el-table-column
        label="手机号"
        align="left"
        prop="phone"
        show-overflow-tooltip
      />
      <el-table-column label="状态" align="center" width="80px">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.interfaceSwitch === 0"
            >启用
          </el-tag>
          <el-tag type="danger" v-else-if="scope.row.interfaceSwitch === 1"
            >停用
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="left" width="220" fixed="right">
        <template slot-scope="scope">
          <template>
            <!--            <el-button-->
            <!--              type="text"-->
            <!--              @click="getInfo(scope.row)"-->
            <!--              >详情-->
            <!--            </el-button>-->

            <el-button type="text" @click="handleDetail(scope.row)">
              资产拓扑
            </el-button>
            <el-button
              type="text"
              @click="handleShake(scope.row)"
              :disabled="scope.row.isDisabledForShake"
              v-hasPermi="['apisecurity:applicationManage:switch']"
            >
              {{ scope.row.interfaceSwitch === 0 ? "停用" : "启用" }}
            </el-button>
            <el-button type="text" @click="viewDetail(scope.row)"
              >详情
            </el-button>
            <el-button
              type="text"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['apisecurity:applicationManage:edit']"
            >
              编辑
            </el-button>
            <el-button
              type="text"
              @click="handleDelete(scope.row)"
              v-hasPermi="['apisecurity:applicationManage:remove']"
              >删除
            </el-button>
          </template>
        </template>
      </el-table-column>
    </common-table>

    <pagination
      slot="pagination"
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <common-edit-dialog
      :title="title"
      :visible.sync="open"
      @cancel="cancel"
      @submit="submitForm"
      :buttonLoading="buttonLoading"
    >
      <el-form
        :model="form"
        label-width="80px"
        ref="form"
        :rules="rules"
        @submit.native.prevent
      >
        <el-row :gutter="18">
          <el-col :span="24">
            <el-form-item label="应用名称" prop="applicationName">
              <common-input
                v-model="form.applicationName"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <common-add-dept
              ref="commonAddDept"
              :deptListParams="deptSelectArr"
              @getCheckedDeptId="getCheckedDeptId"
              :deptId="form.deptId"
            ></common-add-dept>
          </el-col>

          <el-col :span="12">
            <el-form-item label="负责人" prop="userCode">
              <choose-dialog
                :select-value="form.principal"
                @submitDialog="submitDialog"
                @clearInfo="clearInfo"
              >
              </choose-dialog>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item
              v-for="(item, i) in form.serverList"
              :key="i"
              class="server-list"
            >
              <div style="width: 100%">
                <el-row :gutter="18">
                  <el-col :span="12">
                    <el-form-item
                      :label="'域名'"
                      :prop="'serverList.' + i + '.domain'"
                    >
                      <common-input
                        placeholder="请输入"
                        v-model="item.domain"
                        @change="changeDomain"
                      ></common-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="IP" :prop="'serverList.' + i + '.ip'">
                      <common-input
                        placeholder="支持IPV4/IPV6格式"
                        :verify="false"
                        v-model="item.ip"
                        @change="changeIP"
                      >
                      </common-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item
                      label="端口"
                      :prop="'serverList.' + i + '.port'"
                    >
                      <common-input-number
                        :max-length="5"
                        v-model="item.port"
                        placeholder="请输入端口号"
                      >
                      </common-input-number>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
              <!-- <el-form-item class="add-btn">
                <el-button
                  v-if="butOpen"
                  @click="deleteIp(i)"
                  type="danger"
                  plain
                  >删除
                </el-button>
                <el-button type="primary" @click="addIp" plain v-if="i === 0">
                  新增
                </el-button>
              </el-form-item> -->
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <common-input
                v-model="form.remark"
                type="textarea"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </common-edit-dialog>
    <common-info-dialog
      :title="detailstitle"
      :visible.sync="detailsOpen"
      @cancel="cancel"
    >
      <common-info-table>
        <common-info-table-cell label="应用管理名称">
          {{ form.applicationName }}
        </common-info-table-cell>
        <common-info-table-cell label="服务地址" width="50%">
          <div v-for="item in form.serverList">
            <span>{{ item.domain }}</span>
            <span style="margin-left: 12px">{{
              item.ip + ":" + item.port
            }}</span>
          </div>
        </common-info-table-cell>
        <common-info-table-cell label="备注">
          {{ form.remark }}
        </common-info-table-cell>
      </common-info-table>
    </common-info-dialog>

    <distribute-org
      ref="distributeOrg"
      :dialogShow="dialogShow"
      :buttonLoading="submitOrgLoading"
      :deptSelectArr="deptSelectArr"
      @toSubmit="toDistributeOrg"
      @close="dialogShow = false"
    />

    <template v-if="isTopologyDialog">
      <topology :id="topologyId" @close="closeTopologyDialog"></topology>
    </template>

    <application-detail ref="applicationDetail"></application-detail>
  </common-list>
</template>

<script>
import {
  listLication,
  getInfoLication,
  addLication,
  editLication,
  deleteLication,
  getApplicationServer,
  getApplication,
  updateSwitch,
  updateDeptId,
} from "@/api/apisecurity/application/lication";
import { validateIPOrNull, validateDomainOrNull } from "@/utils/formValidates";
import CommonEditDialog from "../../../template/CommonEditDialog.vue";
import topology from "./topology";
import BaseList from "@/mixins/BaseList";
import { getSingleArray, getFullDept } from "@/utils/util";
import DistributeOrg from "./components/distributeOrg.vue";
import applicationDetail from "./components/applicationDetail";
import ChooseDialog from "./components/chooseDialog.vue";
import { decode, encode } from "@/utils/aesUtils";
import Utils from "@/utils";
import {
  list,
  listLevel,
} from "@/api/apisecurity/applicationType/applicationType";
import { remove } from "js-cookie";

export default {
  components: {
    CommonEditDialog,
    topology,
    DistributeOrg,
    applicationDetail,
    ChooseDialog,
  },
  name: "Lication",
  mixins: [BaseList],
  data() {
    // const checkIP = (rule, value, callback) => {
    //   let i = parseInt(rule.field.split(".")[1]);
    //   let item = this.form.serverList[i];
    //   if (!value) {
    //     callback(new Error("请输入IP"));
    //   } else if (
    //     this.form.serverList.filter((f) => f.ip === item.ip).length > 1 &&
    //     this.form.serverList.filter((f) => f.port === item.port).length > 1
    //   ) {
    //     callback(new Error("IP端口不能重复"));
    //   } else if (
    //     this.form.serverList.filter((f) => f.port !== item.port).length > 1
    //   ) {
    //     callback();
    //   } else {
    //     callback();
    //   }
    // };
    // const checkPort = (rule, value, callback) => {
    //   let i = parseInt(rule.field.split(".")[1]);
    //   let item = this.form.serverList[i];
    //   if (!item.port) {
    //     callback(new Error("请输入端口号"));
    //   } else if (
    //     this.form.serverList.filter((f) => f.ip === item.ip).length > 1 &&
    //     this.form.serverList.filter((f) => f.port === item.port).length > 1
    //   ) {
    //     callback(new Error("端口不能重复"));
    //   } else if (
    //     this.form.serverList.filter((f) => f.ip !== item.ip).length > 1
    //   ) {
    //     callback();
    //   } else {
    //     callback();
    //   }
    // };
    // const checkServerName = (rule, value, callback) => {
    //   if (
    //     this.form.serverList.filter((f) => f.serverName === value).length > 1
    //   ) {
    //     callback(new Error("服务名不能重复"));
    //   } else {
    //     callback();
    //   }
    // };
    return {
      dialogShow: false,
      submitOrgLoading: false,
      butOpen: false,
      total: 0,
      detailsOpen: false,
      title: "",
      single: true,
      multiple: true,
      open: false,
      isDisabled: false,
      licationList: [],
      loading: true,
      detailstitle: "",
      showSearch: true,

      form: {
        serverList: [
          {
            ip: "",
            port: 80,
            domain: "",
          },
        ],
        deptId: null,
        principal: "",
        ancestors: "",
      },
      buttonLoading: false,
      rules: {
        applicationName: [
          { required: true, message: "请输入应用名称", trigger: "blur" },
        ],
        "serverList.0.domain": [
          {
            required: false,
            message: "域名格式错误",
            // validator: validateDomainOrNull,
            trigger: "blur",
          },
        ],
        "serverList.0.ip": [
          {
            required: false,
            message: "IP格式错误，支持IPV4/IPV6格式",
            // validator: validateIPOrNull,
            trigger: "blur",
          },
        ],
        // "serverList.0.port": [
        //   {
        //     required: false,
        //     min: 1,
        //     max: 65535,
        //     type: "number",
        //     message: "端口号范围1~65535",
        //     trigger: "blur",
        //   },
        // ],
      },
      ids: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        applicationName: null,
        parentId: null,
        ip: "",
        port: "",
        domain: "",
        deptIds: "",
        principal: "",
        applicationNameEnCode: null,
      },
      isTopologyDialog: false,
      topologyId: "",
      currentParent: 3,
      singleDeptList: [],
      deptSelectArr: [],
      applicationType: [], // 所属分类
      cascaderProps: {
        label: "orgName",
        value: "orgId",
        checkStrictly: true,
        emitPath: false,
      },
    };
  },
  methods: {
    // 应用分类列表
    getTypeList() {
      listLevel({ type: "0" }).then((res) => {
        if (res && res.code === 200) {
          this.applicationType = res.data;
          this.removeChildren(this.applicationType);
        } else {
          this.applicationType = [];
        }
      });
    },

    removeChildren(typeList) {
      let list = typeList || [];
      for (let item of list) {
        if (item.children.length === 0) {
          delete item.children;
        } else {
          this.removeChildren(item.children);
        }
      }
    },

    // ------------------选择弹窗组件--------------------

    submitDialog(info, departName) {
      this.form.principal = info.userName;
    },

    clearInfo() {
      this.form.principal = "";
    },

    changeDomain(val) {
      if (val) {
        this.rules["serverList.0.domain"][0].required = true;
      } else {
        this.rules["serverList.0.domain"][0].required = false;
        this.rules["serverList.0.ip"][0].required = false;
      }
    },
    changeIP(val) {
      if (val) {
        this.rules["serverList.0.ip"][0].required = true;
      } else {
        this.rules["serverList.0.ip"][0].required = false;
        this.rules["serverList.0.domain"][0].required = false;
      }
    },

    getLoading() {
      this.loading = true;
    },
    getCheckedDeptId(val) {
      this.form.deptId = val;
    },
    getDeptList(list) {
      this.deptSelectArr = list;
      this.singleDeptList = getSingleArray(list);
      this.getList();
    },
    getDeptId(val) {
      this.queryParams.deptIds = val;
    },
    getDeptName(val) {
      let dept = this.singleDeptList.find((item) => item.id === val.toString());
      if (dept) return getFullDept(dept.fulllabel);
    },

    //----------------自定义排序-----------------
    sortByIp(obj1, obj2) {
      let num1 = obj1.serverList[0].ip
        ? parseInt(
            obj1.serverList[0].ip
              .split(".")
              .reduce((r, c) => {
                r.push(
                  c.length === 1 ? "00" + c : c.length === 2 ? "0" + c : c
                );
                return r;
              }, [])
              .join("")
          )
        : null;

      let num2 = obj2.serverList[0].ip
        ? parseInt(
            obj2.serverList[0].ip
              .split(".")
              .reduce((r, c) => {
                r.push(
                  c.length === 1 ? "00" + c : c.length === 2 ? "0" + c : c
                );
                return r;
              }, [])
              .join("")
          )
        : null;

      // console.log(num1, num2)
      return num1 - num2;
    },
    sortByPort(obj1, obj2) {
      let num1 = obj1.serverList[0].port
        ? parseInt(obj1.serverList[0].port)
        : null;
      let num2 = obj2.serverList[0].port
        ? parseInt(obj2.serverList[0].port)
        : null;
      // console.log(num1, num2);
      return num1 - num2;
    },

    changeStatus(row) {
      return new Promise((resolve, reject) => {
        updateSwitch({
          id: row.id,
          interfaceSwitch: row.interfaceSwitch,
        })
          .then((res) => {
            if (res && res.code === 200) {
              this.$GlobalSuccessMessage("操作成功");
              this.getList();
              resolve(res);
            } else {
              reject();
              this.$GlobalErrorConfirm("操作失败", res.msg);
            }
          })
          .catch(() => reject());
      });
    },
    //新增服务名、ip、端口
    addIp() {
      this.butOpen = true;
      this.form.serverList.push({
        ip: "",
        port: 80,
        domain: "",
      });
    },
    /**
     * 删除服务名、ip、端口
     * @param i
     */
    deleteIp(i) {
      if (this.form.serverList[i].id) {
        this.getApplicationServer(this.form.serverList[i].id).then((res) => {
          if (res.data === true) {
            this.$GlobalDeleteConfirm("已绑定资产，确定是否删除？")
              .then(() => {
                this.form.serverList.splice(i, 1);
              })
              .catch(() => {});
          } else {
            this.form.serverList.splice(i, 1);
          }
        });
      } else {
        this.form.serverList.splice(i, 1);
        if (this.form.serverList && this.form.serverList.length === 1) {
          this.butOpen = false;
        }
      }
    },
    /**
     * 删除服务名等字段时查询是否被调用
     */
    getApplicationServer(id) {
      return new Promise((resolve, reject) => {
        getApplicationServer({ id: id }).then((res) => {
          if (res && res.code === 200) {
            resolve(res);
          } else {
            reject(res);
          }
        });
      });
    },
    /**
     * 获取列表数据
     */
    getList() {
      this.loading = true;
      listLication(this.queryParams)
        .then((res) => {
          if (res && res.code === 200) {
            this.licationList = res.rows.reduce((r, c) => {
              r.push({
                ...c,
                isDisabledForShake: false,
                serverDomain: c.serverList[0].domain,
                phone: c.phoneNumber
                  ? Utils.phoneEncryption(decode(c.phoneNumber))
                  : "",
              });
              return r;
            }, []);
            this.licationList.forEach((item) => {
              item.deptName = this.getDeptName(item.deptId || "");
            });
            this.total = res && res.total ? res.total : 0;
          } else {
            this.licationList = [];
            this.total = 0;
            this.handleListTips(res);
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /**
     * 重置
     */
    reset() {
      this.form = {
        id: null,
        applicationName: null,
        ip: null,
        port: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        deptId: null,
        serverList: [
          {
            ip: "",
            port: 80,
            domain: "",
          },
        ],
      };
      this.queryParams.applicationNameEnCode = null;
      this.resetForm("form");
    },
    //查询
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.applicationName = this.queryParams.applicationNameEnCode
        ? encode(this.queryParams.applicationNameEnCode)
        : null;
      this.getList();
    },
    //重置
    resetQuery() {
      this.queryParams = this.$options.data().queryParams;
      this.$refs.commonDept.clearDept();
    },
    //取消
    cancel() {
      this.open = false;
      this.detailsOpen = false;
      this.reset();
    },
    //多选
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    //新增
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增应用管理";
    },
    //详情
    getInfo(row) {
      const id = row.id || this.ids;
      getInfoLication({ id }).then((res) => {
        this.form = res.data;
        this.detailsOpen = true;
        this.detailstitle = "应用管理详情";
      });
    },
    //详情
    viewDetail(row) {
      row.deptName = row.deptId ? this.getDeptName(row.deptId) : "";
      this.$refs.applicationDetail.show(row);
    },
    //编辑
    handleUpdate(row) {
      if (row && row.interfaceSwitch === 0) {
        this.$GlobalErrorConfirm("警告", "启用状态不允许编辑");
        return;
      }
      this.reset();
      const id = row.id || this.ids;
      getInfoLication({ id }).then((res) => {
        if (res && res.code === 200) {
          res.data.serverList.forEach((f) => (f.port = parseInt(f.port)));
          this.form = Object.assign(res.data, {
            serverList: res.data.serverList,
          });
          this.open = true;
          this.title = "编辑应用管理";
        } else {
          this.$GlobalErrorConfirm("数据加载失败", res.msg);
        }
      });
    },
    handleDetail(row) {
      this.topologyId = row.id;
      this.isTopologyDialog = true;
    },
    closeTopologyDialog() {
      this.isTopologyDialog = false;
    },
    /**
     * 提交
     */
    submitForm() {
      // console.log(this.form.serverList[0].ip);
      // console.log();
      // if (
      //   (this.form.serverList[0].ip === "" &&
      //     this.form.serverList[0].domain === "") ||
      //   (this.form.serverList[0].ip !== "" &&
      //     this.form.serverList[0].domain !== "")
      // ) {
      //   this.$GlobalErrorConfirm("提示", "域名与IP必填其中一项");
      //   return;
      // }
      this.$refs["form"].validate((valid) => {
        if (valid) {
          let value = "";
          let IpValue = [];
          this.form.serverList.forEach((item) => {
            IpValue.push(item.path);
            value = IpValue.join(",");
          });
          this.buttonLoading = true;
          this.form.path = value;
          if (this.form.id != null) {
            editLication(this.form)
              .then((res) => {
                if (res && res.code === 200) {
                  this.$GlobalSuccessMessage("编辑成功");
                  this.open = false;
                  this.getList();
                } else {
                  this.$GlobalErrorConfirm("编辑失败", res.msg);
                }
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          } else {
            addLication(this.form)
              .then((res) => {
                if (res && res.code === 200) {
                  this.$GlobalSuccessMessage("新增成功");
                  this.open = false;
                  this.getList();
                } else {
                  this.$GlobalErrorConfirm("新增失败", res.msg);
                }
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          }
        }
      });
    },
    //列表删除
    handleDelete(row) {
      // console.log(this.licationList);
      if (row && row.interfaceSwitch === 0) {
        this.$GlobalErrorConfirm("警告", "启用状态不允许删除");
        return;
      }
      let interfaceSwitch = this.licationList.find(
        (v) => this.ids.includes(v.id) && v.interfaceSwitch === 0
      );
      if (interfaceSwitch) {
        this.$GlobalErrorConfirm("删除失败", "启用状态不允许删除");
        return;
      }
      const ids = row.id || this.ids.join(",");
      getApplication({ ids }).then((res) => {
        if (res && res.code === 200) {
          if (res.data === true) {
            this.$GlobalDeleteConfirm("已绑定资产，确认是否删除？")
              .then(() => {
                deleteLication({ ids }).then((res) => {
                  if (res && res.code == 200) {
                    this.$GlobalSuccessMessage("删除成功");
                    if (
                      this.queryParams.pageNum > 1 &&
                      ids.split(",").length === this.licationList.length
                    ) {
                      this.queryParams.pageNum -= 1;
                    }
                    this.getList();
                  } else {
                    this.$GlobalErrorConfirm("删除失败", res.msg).then();
                  }
                });
              })
              .catch(() => {});
          } else {
            this.$GlobalDeleteConfirm()
              .then(() => {
                deleteLication({ ids }).then((res) => {
                  if (res && res.code == 200) {
                    this.$GlobalSuccessMessage("删除成功");
                    if (
                      this.queryParams.pageNum > 1 &&
                      ids.split(",").length === this.licationList.length
                    ) {
                      this.queryParams.pageNum -= 1;
                    }
                    this.getList();
                  } else {
                    this.$GlobalErrorConfirm("删除失败", res.msg).then();
                  }
                });
              })
              .catch(() => {});
          }
        } else {
          this.$GlobalErrorConfirm("删除异常", err.msg).then();
        }
      });
    },

    HandleDistributeOrg() {
      // let includeDistributeOrg = this.licationList.find((v) => {
      //   return this.ids.includes(v.id) && v.deptId;
      // });
      // if (includeDistributeOrg) {
      //   this.$GlobalErrorConfirm("分配失败", "包含已分配组织的数据");
      //   return;
      // }
      this.dialogShow = true;
      this.$refs.distributeOrg.show();
    },
    toDistributeOrg(val) {
      if (val) {
        this.submitOrgLoading = true;
        updateDeptId({ ids: this.ids, deptId: val })
          .then((res) => {
            if (res && res.code === 200) {
              this.$GlobalSuccessMessage("分配成功");
              this.dialogShow = false;
              this.getList();
            } else {
              this.$GlobalErrorConfirm("分配失败", res.msg);
            }
          })
          .catch((err) => {
            this.$GlobalErrorConfirm("分配失败", err.msg);
          })
          .finally(() => {
            this.submitOrgLoading = false;
          });
      } else {
        this.$GlobalErrorConfirm("分配失败", "请选择组织");
      }
    },

    setDisabledOption(data) {
      if (data.length > 0) {
        data.forEach((f) => {
          f.disabled = f.freeze !== "N";
          if (f.children && f.children.length > 0) {
            this.setDisabledOption(f.children);
          }
        });
      }
    },
  },

  created() {
    // this.getList()
    this.getTypeList();
  },
};
</script>
<style lang="scss" scoped>
.ipList {
  display: flex;
  align-items: center;
  padding-right: 70px;

  .deleteIp {
    position: absolute;
    right: 0;
  }
}

.server-list {
  margin-bottom: 0 !important;

  ::v-deep .el-form-item__content {
    margin-left: 0 !important;
    display: flex;
  }

  .add-btn {
    ::v-deep .el-form-item__content {
      margin-left: 8px !important;
    }
  }
}

.port {
  ::v-deep .common-input-number {
    width: 100%;
  }
}
</style>
